package com.sgcc.dlsc.monitorredis.controller;

import com.sgcc.dlsc.monitorredis.model.po.ClusterConfig;
import com.sgcc.dlsc.monitorredis.model.bo.Group;
import com.sgcc.dlsc.monitorredis.model.po.Host;
import com.sgcc.dlsc.monitorredis.service.GetInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;

/**
 * @Author: 李孟帅
 * @CreateTime: 2019-08-26 16:14
 * @Description: ${Description}
 */
@RestController
@CrossOrigin(maxAge = 3600)
@RequestMapping("/redis")
@Api("缓存服务相关的接口文档")
public class GetInfoController {
    @Resource
    private GetInfoService getInfoService;

    @PostMapping("/addNode")
    @ApiOperation(value = "添加一个redis节点，并返回节点状态信息")
    public String addNode(@RequestBody Host host) {
        try {
            return getInfoService.addNode(host);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    @GetMapping("/findNodes")
    @ApiOperation("检查可用的主机节点")
    public List<Host> selectNodes() {
        try {
            return getInfoService.selectNodes();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @PostMapping("/createCluster")
    @ApiOperation("选择节点创建redis集群")
    public String createCluster(@RequestBody ClusterConfig clusterConfig) {
        System.out.println(clusterConfig);
        try {
            return getInfoService.createRedisCluster(clusterConfig);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    @GetMapping("/getClusterList")
    @ApiOperation("获取集群列表")
    public Map<String, List<Group>> getClusterList() {
        return getInfoService.getClusterList();
    }
}
